package com.homedo.microservice.open.service.gateway.persistence.dao;

import com.homedo.common.dao.BaseDao;
import com.homedo.common.util.Detect;
import com.homedo.microservice.open.service.gateway.bean.enums.forzuulfilterdefault.ProgressEnum4ZuulFilterDefault;
import com.homedo.microservice.open.service.gateway.bean.enums.forzuulfilterdefault.StatusEnum4ZuulFilterDefault;
import com.homedo.microservice.open.service.gateway.bean.po.ZuulFilterDefault;
import com.homedo.microservice.open.service.gateway.persistence.mapper.IZuulFilterDefaultMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.stream.Collectors;


/**
 * @author 作者 jgshun
 * @date 创建时间 2018年09月14日 14时43分20秒
 */
@Repository
public class ZuulFilterDefaultDao extends BaseDao<ZuulFilterDefault> {
    @Autowired
    private IZuulFilterDefaultMapper zuulFilterDefaultMapper;


    public List<ZuulFilterDefault> getList4Application(String applicationName, List<ProgressEnum4ZuulFilterDefault> progresses, List<StatusEnum4ZuulFilterDefault> statuses) {
        Example example = new Example(ZuulFilterDefault.class);
        Example.Criteria criteria = example.createCriteria();

        criteria.andEqualTo(ZuulFilterDefault.FIELD_APPLICATIONNAME, applicationName);

        if (Detect.notEmpty(progresses)) {
            criteria.andIn(ZuulFilterDefault.FIELD_PROGRESS, progresses.stream().map(ProgressEnum4ZuulFilterDefault::getCode).collect(Collectors.toList()));
        }

        if (Detect.notEmpty(statuses)) {
            criteria.andIn(ZuulFilterDefault.FIELD_STATUS, statuses.stream().map(StatusEnum4ZuulFilterDefault::getCode).collect(Collectors.toList()));
        }

        return super.getListByExample(example);
    }
}
